"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/2/13 13:31
@Description : 数据容器
 元组的使用
   1. 有序
   2.可以重复
   3.不限定数据类型
   4.元素不能改变
"""
#  tuple
tuple_fruit = ('apple', 'apple', 'orange', 'pear', [1, 2, 3])
print(tuple_fruit, type(tuple_fruit))

#  访问元组中的数据  index
print(tuple_fruit[0])

# IndexError: tuple index out of range
# print(tuple_fruit[7])

print(tuple_fruit[-1])
print('*' * 30)
# 通过索引遍历元组
len_fruit = len(tuple_fruit)
for index in range(len_fruit):
    print(tuple_fruit[index])

print('*' * 30)
#  将元组作为可迭代数据遍历
for fruit in tuple_fruit:
    print(fruit)

# 通过索引修改元组中数据的值  TypeError: 'tuple' object does not support item assignment  不支持
# tuple_fruit[0] = 'banana'
# print(tuple_fruit)

# 元组切片  可参照列表
sub_tuple = tuple_fruit[0:3]
print(f'{tuple_fruit}[0-3] = {sub_tuple} ')

# 创建空元组
# empty_tuple = ()
empty_tuple = tuple()
print(empty_tuple, type(empty_tuple))

# 创建含有一个元素的元组  在元素后面需要添加一个逗号，否则会被处理基本数据类型
one_item_tuple = ('1',)
print(one_item_tuple, type(one_item_tuple))

# 删除元组
del one_item_tuple
# 删除后的元组，再次使用时会抛出异常信息  NameError: name 'one_item_tuple' is not defined
# print(one_item_tuple)
#  del 删除指定位置的列表元素
list_info = ['apple', 'orange', 'pear', 1, 2, 3]
# list_info.pop()
# list_info.remove(3)
del list_info[-1]
print(list_info)

tuple_1 = (1, 2, 3)
tuple_2 = (4, 5, 6)
tuple_result = tuple_1 + tuple_2
print(tuple_result)

tuple_result = tuple_1 * 2
print(tuple_result)
#  成员运算
print(1 in tuple_result)

print(max(tuple_result))
print(min(tuple_result))

tuple_1 = (1, 2, 3)
tuple_1 = (4, 5, 6)

print(tuple_1)
